import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.ServerSocket;
import java.net.Socket;

//TCP Socket is opend

public class TCPServerThread extends Thread {
	private static int port=4444, maxConnections=0;
	int i=0;
	Socket server;
	ServerSocket listener;
	private boolean done=false;
	
	public TCPServerThread(){
		try {
			listener= new ServerSocket(port);
			System.out.println("Connection OK");
		} catch (IOException e) {
			System.err.println("Could not listen on port: 10007."); 
			e.printStackTrace();
		}
	}
	public void run() {
			 while(true)
			 {
				 while((i++ < maxConnections) || (maxConnections == 0)){
					 try{
				        server = listener.accept();
				        TCPServerThreadClient conn_c= new TCPServerThreadClient(server);
				        conn_c.start();
					 } catch (IOException ioe) {
				      System.out.println("IOException on socket listen: " + ioe);
				      ioe.printStackTrace();
				    }
				    done = true;
				 }
			 }
	}
	
	public String getValue()
	{
		return null;
	}
	
	public void setDone(boolean done){ this.done=done;}
	
	public boolean getDone(){return done;}
}
